//
//  RefundsViewController.m
//  体育商城
//
//  Created by  on 2022/9/24.
//

#import "RefundsViewController.h"
#import "QRViewController.h"
#import "RefundResultPopViewController.h"

@interface RefundsViewController ()<UITextViewDelegate>
@property (strong, nonatomic) IBOutlet UILabel *money;
@property (strong, nonatomic) IBOutlet UILabel *status;
@property (strong, nonatomic) IBOutlet UILabel *orderNum;
@property (strong, nonatomic) IBOutlet UITextView *input;
@property (strong, nonatomic) IBOutlet UILabel *placeholder;
@property (strong, nonatomic) IBOutlet UIButton *scanBtn;
@end

@implementation RefundsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    self.orderNum.text = self.model.orderID;
    self.money.text = [NSString stringWithFormat:LS(@"¥:%@"),self.model.price];
    if (self.model.orderStatus == GoodsOrderStastusPayed) {
        self.status.text = LS(@"已付款");
    }else if (self.model.orderStatus == GoodsOrderStastusNoShip){
        self.status.text = LS(@"待发货");
    }else if (self.model.orderStatus == GoodsOrderStastusNoReceipt){
        self.status.text = LS(@"待收货");
    }else if (self.model.orderStatus == GoodsOrderStastusAfterSales){
        self.status.text = LS(@"退款中");
    }
}
- (void)initUI{
    self.title = LS(@"申请退货退款");
}

- (IBAction)actionForBtn:(UIButton *)sender {
    if (sender.tag == 201) {///扫描二维码
        WS(self)
        QRViewController *vc = [QRViewController new];
        vc.block =^(NSString * _Nonnull text) {
            weakself.orderNum.text = text;
        };
        [self.navigationController pushViewController:vc animated:YES];
    }else{///提交
        WS(self)
        RefundResultPopViewController *vc = [RefundResultPopViewController new];
        [self presentViewController:vc animated:NO completion:nil];
        [GoodsTool delete:self.model complete:^{
            weakself.model.account = APP.user.account;
            weakself.model.orderID = [NSDate currentTimeStamp:@"yyyy/MM/dd HH:mm:ss"];
            weakself.model.orderStatus = GoodsOrderStastusAfterSales;
            [weakself.model bg_saveOrUpdateAsync:^(BOOL isSuccess) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    [weakself backBtnAction];
                    [[NSNotificationCenter defaultCenter] postNotificationName:notifyJoinCartUpdate object:nil];
                });
            }];
        }];
    }
}
#pragma mark - UITableViewDataSource
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    self.placeholder.hidden = YES;
    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    self.placeholder.hidden = textView.text.length > 0;
    return YES;
}
@end
